<?php

namespace App\Repository;

use App\Consts\GlobalConst;
use App\Consts\GlobalProConst;
use App\Models\Pro;
use App\Models\Select\ProSelect;

/**
 * @package App\Repository
 * @see ProRepository
 */
class ProRepository extends BaseRepository
{
    /**
     * 获取智囊团列表
     * @param $searchParams
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function getProList($searchParams)
    {
        $provider = Pro::getInstance()
            ->where('status', GlobalProConst::STATUS_NORMAL)
            ->where('is_deleted', GlobalConst::IS_NOT_DELETE);

        $provider->orderBy('weight', GlobalConst::ORDER_TYPE_DESC);

        return $this->setPagination($provider);
    }

    /**
     * 获取智囊团列表
     * @param $searchParams
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function getRecommendProList($searchParams)
    {
        $provider = Pro::getInstance()
            ->where('status', GlobalProConst::STATUS_NORMAL)
            ->where('is_deleted', GlobalConst::IS_NOT_DELETE)
            ->where('is_recommend', GlobalProConst::IS_RECOMMEND);

        $provider->orderBy('weight', GlobalConst::ORDER_TYPE_DESC);

        return $this->setPagination($provider, ['page' => $searchParams['page'], 'page_size' => $searchParams['page_size']]);
    }

    /**
     * 通过用户ID获取智囊团
     * @param $userId
     * @param $selectScene
     * @return \Illuminate\Database\Eloquent\Builder|Pro|object|null
     */
    public function getProByUserId($userId, $selectScene = ProSelect::SELF_DETAIL)
    {
        return Pro::getInstance()
            ->select(ProSelect::getSelects($selectScene))
            ->where('user_id', $userId)
            ->first();
    }
}
